#include "Renderer.h"

//
//	Constructor
//
Renderer::Renderer(	uint width, uint height, string title, uint mode,
					uint redbits, uint greenbits, uint bluebits, uint alphabits, 
					uint depthbits, uint stencilbits) {

	init = false;

	if(!glfwInit()) {
		DEBUG_LOG("Error: GLFW could not initialize.");
		return;
	};

	glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);					// Don't allow window resizing
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, OPENGL_MAJOR_VER);	// We want this opengl version
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, OPENGL_MINOR_VER);	// And this minor version
	glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);			// Don't include deprecated functionality
	glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);	// We want an OpenGL core profile
	
	if(!glfwOpenWindow(	
			width, height, 
			redbits, greenbits, bluebits, alphabits,
			depthbits, stencilbits, mode 
			)) {
		glfwTerminate();
		DEBUG_LOG("Error: GLFW failed to initialize the window.");
		return;	
	}

	glfwSetWindowTitle(title.c_str());
	glfwSetWindowPos(WINDOW_DEFAULT_POS_X, WINDOW_DEFAULT_POS_Y);

	glfwGetWindowSize((int*)(&this->width), (int*)(&this->height));

	// Initialize GLEW
	GLenum err = glewInit();
	if(err != GLEW_OK) {
		DEBUG_LOG("Error: Failed to initialize GLEW.");
		return;
	}

	// Check if GLEW version 3.2 is supported
	if(!GLEW_VERSION_3_2) {
		DEBUG_LOG("Error: GLEW 3.2 not supported");
		return;
	}

	init = true;

};

//
//	Destructor
//
Renderer::~Renderer(void) {
	glfwTerminate();
};
